import 'package:flutter/material.dart';

class AnimatedOpacityApp extends StatefulWidget {
  AnimatedOpacityApp({Key key,this.title}):super(key:key);
  final String title;

  @override
  _AnimatedOpacityAppState createState() => _AnimatedOpacityAppState();
}

class _AnimatedOpacityAppState extends State<AnimatedOpacityApp> {
  bool _visible = true;
  @override
  Widget build(BuildContext context) {

    return Material(
      child: Scaffold(
        appBar: AppBar(title: Text('AnimatedOpacity')),
        body: Center(
          child: AnimatedOpacity(
            opacity: _visible?1.0:0.0,
            duration: Duration(milliseconds: 500),
            child: Container(
              width: 200.0,
              height: 200.0,
              color: Colors.green,
            ),
          ),
        ),
        floatingActionButton: FloatingActionButton(
          tooltip: 'Toggle Opcity',
          child: Icon(Icons.flip),
          onPressed: (){
            setState(() {
              _visible = !_visible;
            });
          },
        ),
      ),
    );
  }
}
